package com.talent.service.iot.mqtt.model.request;

import com.talent.service.iot.mqtt.model.fix.TlMqttFixedHead;
import com.talent.service.iot.mqtt.model.payload.TlMqttPublishPayload;
import com.talent.service.iot.mqtt.model.variable.TlMqttPublishVariableHead;
import io.netty.handler.codec.mqtt.MqttMessageType;
import io.netty.handler.codec.mqtt.MqttQoS;

/**
 * @ClassName：TlMqttPublishReq
 * @Author: hszhou
 * @Date: 2024/11/26 13:23
 * @Description: 发布消息
 */
public class TlMqttPublishReq   {


    private TlMqttFixedHead fixedHead;
    private TlMqttPublishVariableHead variableHead;
    private TlMqttPublishPayload payload;
    public TlMqttPublishReq(){}

    public TlMqttPublishReq(TlMqttFixedHead fixedHead, TlMqttPublishVariableHead variableHead, TlMqttPublishPayload payload) {
        this.fixedHead = fixedHead;
        this.variableHead = variableHead;
        this.payload = payload;
    }

    public static TlMqttPublishReq of(String topic,
                                            MqttQoS qoS,
                                            boolean retain,
                                            String content,
                                            int messageId){
        TlMqttFixedHead fixedHead = TlMqttFixedHead.of(MqttMessageType.PUBLISH,qoS,retain);
        TlMqttPublishVariableHead variableHead = TlMqttPublishVariableHead.of(topic, messageId);
        TlMqttPublishPayload payload = TlMqttPublishPayload.of(content);
        return new TlMqttPublishReq(fixedHead,variableHead,payload);
    }

    public TlMqttFixedHead getFixedHead() {
        return fixedHead;
    }

    public void setFixedHead(TlMqttFixedHead fixedHead) {
        this.fixedHead = fixedHead;
    }

    public TlMqttPublishVariableHead getVariableHead() {
        return variableHead;
    }

    public void setVariableHead(TlMqttPublishVariableHead variableHead) {
        this.variableHead = variableHead;
    }

    public TlMqttPublishPayload getPayload() {
        return payload;
    }

    public void setPayload(TlMqttPublishPayload payload) {
        this.payload = payload;
    }

    @Override
    public String toString() {
        return "TlMqttPublishReq{" +
                "fixedHead=" + fixedHead +
                ", variableHead=" + variableHead +
                ", payload=" + payload +
                '}';
    }


}
